Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema: [],
    title: '',
    result: '',
    options: {},
    apiType: '',
    remark: '',
    webUrl: '',
    apiName: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })

    this.setData({
      apiType: options.zh,
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if(wx.getStorageSync('routeInfo') && this.data.apiType == 'router.getRouteContext') {
      this.setData({
        result: wx.getStorageSync('routeInfo'),
        apiName: 'router.getRouteContext'
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  getRouteFunc(e) {
    let that = this;
    const routeInfo = wx.router;
    console.log('routeInfo', routeInfo)
    that.setData({
      result: routeInfo,
      apiName: e.currentTarget.dataset.apiname
    })
  },
  addRouterFunc(e) {
    let that = this;
    const systemInfo = wx.getSystemInfoSync();
    console.log('systemInfo', systemInfo)
    const slideRouteBuilder = (customRouteContext) => {
      const { primaryAnimation } = customRouteContext
      const handlePrimaryAnimation = () => {
        'worklet'
        const transX = systemInfo.windowWidth * (1 - primaryAnimation.value)
         return {
           transform: `translateX(${transX}px)`,
         }
      }
      return {
        handlePrimaryAnimation
      }
    }
    wx.router.addRouteBuilder('slide', slideRouteBuilder)
    console.log('新增自定义路由', wx.router)

    setTimeout(() => {
      wx.navigateTo({
        url: '/packageAPI/pages/route/customRouter/scale-page/index',
        routeType: 'slide'
      })
    }, 1000)
  },
  getRouterInfoFunc(e) {
    let that = this;
    const systemInfo = wx.getSystemInfoSync();
    console.log('systemInfo', systemInfo)
    const slideRouteBuilder = (customRouteContext) => {
      const { primaryAnimation } = customRouteContext
      const handlePrimaryAnimation = () => {
        'worklet'
        const transX = systemInfo.windowWidth * (1 - primaryAnimation.value)
         return {
           transform: `translateX(${transX}px)`,
         }
      }
      return {
        handlePrimaryAnimation
      }
    }
    wx.router.addRouteBuilder('slide', slideRouteBuilder)
    setTimeout(() => {
      wx.navigateTo({
        url: '/packageAPI/pages/route/customRouter/scale-page/index',
        routeType: 'slide'
      })
    }, 1000)
  },
  removeRouterInfoFunc(e) {
    let that = this;
    const systemInfo = wx.getSystemInfoSync();
    console.log('systemInfo', systemInfo)
    const slideRouteBuilder = (customRouteContext) => {
      const { primaryAnimation } = customRouteContext
      const handlePrimaryAnimation = () => {
        'worklet'
        const transX = systemInfo.windowWidth * (1 - primaryAnimation.value)
         return {
           transform: `translateX(${transX}px)`,
         }
      }
      return {
        handlePrimaryAnimation
      }
    }
    wx.router.addRouteBuilder('slide', slideRouteBuilder)
    setTimeout(() => {
      console.log('删除路由 ', wx.router.removeRouteBuilder('slide'))
    }, 1000)
  }
})